/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            userIntegralInfo: {
                integrals: [],
                total: 0,
                records: 1,
                moreCondition: false,
                integralId: '',
                conditions: {
                    integralName: '',
                    objType: '6006',
                    objId: '',
                    amount: '',
                    mallApiCode:'queryIntegralBmoImpl'
                }
            }
        },
        _initMethod: function () {
            $that._listIntegrals(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('userIntegral', 'listIntegral', function (_param) {
                $that._listIntegrals(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listIntegrals(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listIntegrals: function (_page, _rows) {
                $that.userIntegralInfo.conditions.page = _page;
                $that.userIntegralInfo.conditions.row = _rows;
                let param = {
                    params: $that.userIntegralInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/mall.getAdminMallOpenApi',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.userIntegralInfo.total = _json.total;
                        $that.userIntegralInfo.records = _json.records;
                        $that.userIntegralInfo.integrals = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.userIntegralInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _queryIntegralMethod: function () {
                $that._listIntegrals(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.userIntegralInfo.moreCondition) {
                    $that.userIntegralInfo.moreCondition = false;
                } else {
                    $that.userIntegralInfo.moreCondition = true;
                }
            },
            _toMerchantModal: function() {
                let _objType = $that.userIntegralInfo.conditions.objType;
                if(_objType == '6006'){
                    vc.jumpToMall('/#/pages/admin/userIntegral?tab=用户积分')
                }else{
                    vc.jumpToMall('/#/pages/admin/storeIntegral?tab=商家积分')
                }
            },
            _switchIntegralObjType:function(_objType){
                $that.userIntegralInfo.conditions.objType = _objType;
                $that._listIntegrals(DEFAULT_PAGE, DEFAULT_ROWS);
            }
        }
    });
})(window.vc);
